package homework.service;

import homework.model.Penguin;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Map
 */
public class PenguinManage2 {

    public static void main(String[] args) {

        Penguin p1 = new Penguin("欧欧", "Q仔");
        Penguin p2 = new Penguin("亚亚", "Q妹");
        Penguin p3 = new Penguin("菲菲", "Q妹");
        Penguin p4 = new Penguin("美美", "Q妹");

        Map<String,Penguin> map=new HashMap<>();
        map.put("A",p1);
        map.put("B",p2);
        map.put("C",p3);
        map.put("D",p4);

        System.out.println("使用Iterator遍历，所有企鹅的昵称和品种分别是：");
        Collection<Penguin> penguins = map.values();
        Iterator<Penguin> iterator = penguins.iterator();
        while (iterator.hasNext()){
            Penguin p = iterator.next();
            System.out.println(p.getName()+" "+p.getGender());
        }

    }

}
